package cn.nuist.utils;

import java.util.List;

/**
 * Page页  查询列表数据时 Page信息
 * @param <T>
 */

public class Page<T> {
    //page对象所承载的页面数据
    private List<T> list;
    //当前页
    private Integer currentPage;
    //前一夜
    private Integer prePage;
    //后一页
    private Integer nextPage;
    //每页显示的条数
    private Integer pageSize = 5;
    //总条数
    private Integer totalCount;
    //总页数
    private Integer totalPageCount;

    public void setCurrentPage(Integer currentPage) {
        if(currentPage<1){
            this.currentPage = 1;
        }else{
            this.currentPage = currentPage;
            this.prePage = this.currentPage == 1?1:currentPage-1;
            this.nextPage = this.totalPageCount==currentPage?this.totalPageCount:this.currentPage+1;
        }
    }

    public Page(List<T> list, Integer currentPage, Integer prePage, Integer nextPage, Integer pageSize, Integer totalCount, Integer totalPageCount) {
        this.list = list;
        this.currentPage = currentPage;
        this.prePage = prePage;
        this.nextPage = nextPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPageCount = totalPageCount;
    }

    public Page(List<T> list) {
        this.list = list;
    }

    public Page() {
    }

    public List<T> getList() {
        return list;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public Integer getPrePage() {
        return prePage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public Integer getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalCount(Integer totalCount) {
        if(totalCount<0){
            this.totalCount = 0;
        }else{
            this.totalCount = totalCount;
            totalPageCount = (totalCount%this.pageSize==0) ?totalCount/this.pageSize:(totalCount/this.pageSize+1);
        }
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setTotalPageCount(Integer totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    @Override
    public String toString() {
        return "Page{" +
                "list=" + list +
                ", currentPage=" + currentPage +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPageCount=" + totalPageCount +
                '}';
    }
}
